import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/services.dart';

class FlutterGallerySaver {
  static const MethodChannel _channel =
      const MethodChannel('flutter_gallery_saver');

  static FutureOr<dynamic> saveImage(
    Uint8List imageBytes, {
    int quality = 80,
    String name = "",
    bool isReturnImagePathOfIOS = false,
  }) async {
    final result =
        await _channel.invokeMethod("saveImageToGallery", <String, dynamic>{
      'imageBytes': imageBytes,
      'quality': quality,
      'name': name,
      'isReturnImagePathOfIOS': isReturnImagePathOfIOS
    });
    return result;
  }

  static Future saveImageWithUrl(String file,
      {bool isReturnPathOfIOS = false}) async {
    final result = await _channel.invokeMethod(
        'saveImageToGalleryForUrl', <String, dynamic>{
      'file': file,
      'isReturnPathOfIOS': isReturnPathOfIOS
    });
    return result;
  }

  static Future saveVideo(String file, {bool isReturnPathOfIOS = false}) async {
    final result = await _channel.invokeMethod(
        'saveVideoToGallery', <String, dynamic>{
      'file': file,
      'isReturnPathOfIOS': isReturnPathOfIOS
    });
    return result;
  }
}
